package com.Thread.Demo7;

/**
 * @ClassName Account
 * @Description TODO
 * @Author Kx
 * @Date 2025/3/12 11:31
 * @Version 1.0
 */
public class Account {
    private double balance; // 账户余额

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public synchronized void withdraw(double money) {
        if (this.balance >= money) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            this.balance -= money;
            System.out.println(Thread.currentThread().getName() + "取钱成功，余额为：" + this.balance);
        } else {
            System.out.println(Thread.currentThread().getName() + "取钱失败，余额不足");
        }
    }
}
